home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / stdg44.exe / lha / STDG.H < prev    next >
C/C++ Source or Header  |  1994-01-10  |  9KB  |  321 lines

  1. /*
  2.  *  Stdg
  3.  *  ----
  4.  *  Version 4 (c) Lachlan Patrick 1993
  5.  *
  6.  */
  7.  
  8. /*
  9.  *  Assume C declarations for C++
  10.  */
  11.  
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15.  
  16. /*
  17.  *  Unsigned types.
  18.  */
  19.  
  20. #ifndef _U_H
  21. #define _U_H
  22.  
  23. typedef unsigned char   uchar;
  24. typedef unsigned short  ushort;
  25. typedef unsigned int    uint;
  26. typedef unsigned long   ulong;
  27.  
  28. #endif
  29.  
  30. /*
  31.  *  Definition of Null
  32.  */
  33.  
  34. #ifndef NULL
  35. #define NULL (0)
  36. #endif
  37.  
  38. /*
  39.  *  Redefine main for portability and safety.
  40.  */
  41.  
  42. #define main gmain
  43.  
  44. int main(int argc, char **argv);
  45.  
  46. /*
  47.  *  Standard graphics library.
  48.  */
  49.  
  50. #ifndef _STDG_H
  51. #define _STDG_H
  52.  
  53. /*
  54.  *  Types.
  55.  */
  56.  
  57. typedef struct  point       point;
  58. typedef struct  rectangle   rectangle;
  59. typedef struct  mouse       mouse;
  60. typedef struct  bitmap      bitmap;
  61. typedef struct  window      window;
  62. typedef struct  menuitem    menuitem;
  63. typedef         menuitem *  menu;
  64. typedef struct  cursor      cursor;
  65. typedef struct  font        font;
  66.  
  67. typedef ulong               pixval;
  68.  
  69. typedef void                voidfn(void);
  70. typedef void                winfn(window *);
  71.  
  72. struct  point
  73. {
  74.     long        x;              /* horizontal co-ordinate */
  75.     long        y;              /* vertical co-ordinate */
  76. };
  77.  
  78. struct  rectangle
  79. {
  80.     point       min;            /* top-left point inside rectangle */
  81.     point       max;            /* bottom-right outside rectangle */
  82. };
  83.  
  84. struct  mouse
  85. {
  86.     uchar       kind;           /* mouse event kind bit array */
  87.     uchar       buttons;        /* mouse button state bit array: LMR=124 */
  88.     point       xy;             /* location of mouse */
  89. };
  90.  
  91. struct  bitmap
  92. {
  93.     rectangle   r;              /* rectangle in data area, local coords */
  94.     short       depth;          /* depth = number of bits per pixel */
  95.     uchar *     bits;           /* bitmap data */
  96. };
  97.  
  98. struct  window
  99. {
  100.     bitmap *    b;              /* bitmap for the window */
  101.     rectangle   r;              /* window rectangle on screen */
  102.     ushort      flags;          /* window appearance bit array */
  103.     short       kind;           /* user data can be stored here */
  104.     void *      data;           /* user data can be stored here */
  105.     winfn *     close;          /* called before window is closed */
  106.     winfn *     resize;         /* called after window is resized */
  107.     winfn *     redraw;         /* called when window must be redrawn */
  108. };
  109.  
  110. struct  menuitem
  111. {
  112.     char *      name;           /* name of menu item, NULL=end of list */
  113.     ushort      key;            /* key equivalent, 0=none */
  114.     short *     state;          /* pointer to state variable */
  115.     voidfn *    action;         /* action to perform when item is chosen */
  116. };
  117.  
  118. struct  cursor
  119. {
  120.     point       offset;         /* bitmap offset from mouse location */
  121.     uchar       white[2*16];    /* white mask */
  122.     uchar       black[2*16];    /* black shape */
  123.     void *      cp;             /* library data: initialise to NULL */
  124. };
  125.  
  126. struct  font
  127. {
  128.     short       height;         /* height of a line */
  129.     short       ascent;         /* top of bitmap to baseline */
  130.     short       descent;        /* baseline to descender */
  131. };
  132.  
  133. /*
  134.  *  Colours.
  135.  */
  136.  
  137. #define BLACK       0x00000000L
  138. #define WHITE       0xFFFFFF00L
  139. #define BLUE        0x0000FF00L
  140. #define YELLOW      0xFFFF0000L
  141. #define GREEN       0x00FF0000L
  142. #define MAGENTA     0xFF00FF00L
  143. #define RED         0xFF000000L
  144. #define CYAN        0x00FFFF00L
  145.  
  146. #define GREY        0x7F7F7F00L
  147. #define GRAY        0x7F7F7F00L
  148. #define LTGREY      0xBFBFBF00L
  149. #define LTGRAY      0xBFBFBF00L
  150. #define DKGREY      0x3F3F3F00L
  151. #define DKGRAY      0x3F3F3F00L
  152.  
  153. /*
  154.  *  Transfer codes for drawing operations.
  155.  */
  156.  
  157. #define Zeros       0x00
  158. #define DnorS       0x01
  159. #define DandnotS    0x02
  160. #define notS        0x03
  161. #define notDandS    0x04
  162. #define notD        0x05
  163. #define DxorS       0x06
  164. #define DnandS      0x07
  165. #define DandS       0x08
  166. #define DxnorS      0x09
  167. #define D           0x0A
  168. #define DornotS     0x0B
  169. #define S           0x0C
  170. #define notDorS     0x0D
  171. #define DorS        0x0E
  172. #define Ones        0x0F
  173.  
  174. /*
  175.  *  Mouse buttons and event constants.
  176.  */
  177.  
  178. #define NoButton        0x00
  179. #define LeftButton      0x01
  180. #define MiddleButton    0x02
  181. #define RightButton     0x04
  182.  
  183. #define MouseMove       0x00
  184. #define MouseDown       0x10
  185. #define MouseUp         0x20
  186. #define MouseTimer      0x40
  187. #define DoubleClick     0x80
  188.  
  189. #define LeftButtonDown      (MouseDown | LeftButton)
  190. #define MiddleButtonDown    (MouseDown | MiddleButton)
  191. #define RightButtonDown     (MouseDown | RightButton)
  192. #define LeftButtonUp        (MouseUp | LeftButton)
  193. #define MiddleButtonUp      (MouseUp | MiddleButton)
  194. #define RightButtonUp       (MouseUp | RightButton)
  195.  
  196. /*
  197.  *  Window flags.
  198.  */
  199.  
  200. #define Simple          0x0000
  201. #define Visible         0x0001
  202. #define Buffered        0x0002
  203. #define Titlebar        0x0004
  204. #define Closebox        0x0008
  205. #define Maximize        0x0010
  206. #define Resize          0x0020
  207. #define Attentive       0x0040
  208. #define DoubleClicks    0x0080
  209. #define Modal           0x0100
  210. #define Floating        0x0200
  211. #define Workspace       0x0400
  212. #define Document        0x0800
  213.  
  214. /*
  215.  *  Menu item states.
  216.  */
  217.  
  218. #define Disabled    0x00
  219. #define Enabled     0x01
  220. #define Ticked      0x02
  221.  
  222.  
  223. /*
  224.  *  Function prototypes.
  225.  */
  226.  
  227. void    ginit(char *name, voidfn *update_menus, menu menus[]);
  228. void    gexit(void);
  229. void    gflush(void);
  230.  
  231. extern  void    (*gerror)(char *errstr);
  232.  
  233. #define dx(r)   ((r).max.x-(r).min.x)
  234. #define dy(r)   ((r).max.y-(r).min.y)
  235.  
  236. point       pt(long x, long y);
  237. rectangle   rect(long minx, long miny, long maxx, long maxy);
  238. rectangle   rdiag(long minx, long miny, long width, long height);
  239. rectangle   rpt(point min, point max);
  240.  
  241. point       addp(point p1, point p2);
  242. point       subp(point p1, point p2);
  243. point       mulp(point p, long i);
  244. point       divp(point p, long i);
  245. rectangle   raddp(rectangle r, point p);
  246. rectangle   rsubp(rectangle r, point p);
  247. rectangle   mulr(rectangle r, long i);
  248. rectangle   divr(rectangle r, long i);
  249. rectangle   insetr(rectangle r, long i);
  250. rectangle   rcanon(rectangle r);
  251. short       pinr(point p, rectangle r);
  252. short       rxr(rectangle r1, rectangle r2);
  253. short       eqp(point p1, point p2);
  254. short       eqr(rectangle r1, rectangle r2);
  255. short       rclip(rectangle *r1, rectangle r2);
  256.  
  257. void    bit_copy(bitmap *db, point p, bitmap *sb, rectangle r, pixval v);
  258. void    texture_rect(bitmap *db, rectangle r, bitmap *sb, pixval v);
  259. void    invert_rect(bitmap *db, rectangle r);
  260. void    fill_rect(bitmap *db, rectangle r, pixval v);
  261. void    draw_rect(bitmap *db, rectangle r, long w, pixval v);
  262.  
  263. void    draw_point(bitmap *db, point p, pixval v);
  264. void    draw_line(bitmap *db, point p1, point p2, pixval v);
  265. void    draw_arc(bitmap *db, point p0, point p1, point p2, pixval v);
  266. void    fill_circle(bitmap *db, point p, long r, pixval v);
  267. void    draw_circle(bitmap *db, point p, long r, pixval v);
  268. void    fill_ellipse(bitmap *db, point p, long r1, long r2, pixval v);
  269. void    draw_ellipse(bitmap *db, point p, long r1, long r2, pixval v);
  270. point   draw_string(bitmap *db, point p, font *f, char *s, pixval v);
  271. long    strwidth(font *f, char *s);
  272. point   strsize(font *f, char *s);
  273.  
  274. bitmap *new_bitmap(rectangle r, short depth);
  275. bitmap *get_bitmap(char *name, short depth);
  276. void    del_bitmap(bitmap *b);
  277.  
  278. window *new_window(char *name, rectangle r, ushort flags);
  279. void    set_winfns(window *w, winfn *close, winfn *size, winfn *draw);
  280. void    set_winname(window *w, char *newname);
  281. void    del_window(window *w);
  282. void    show_window(window *w);
  283. void    hide_window(window *w);
  284.  
  285. short   start_timer(long msec);
  286. short   set_mouse_delay(long msec);
  287. void    delay(long msec);
  288. short   can_event(void);
  289. short   can_timer(void);
  290. short   can_mouse(window *w);
  291. short   can_key(window *w);
  292. long    get_timer(void);
  293. mouse   get_mouse(window *w);
  294. ushort  get_key(window *w);
  295. void    unget_mouse(window *w, mouse m);
  296. void    unget_key(window *w, ushort k);
  297.  
  298. cursor *get_cursor(char *name);
  299. void    set_cursor(cursor *c);
  300.  
  301. font *  get_font(char *name, char *style, ushort size);
  302.  
  303.  
  304. /*
  305.  *  Library supplied variables.
  306.  */
  307.  
  308. extern  bitmap *screen;
  309. extern  font   *sys_font;
  310. extern  font   *fixed_font;
  311. extern  cursor *current_cursor;
  312. extern  window *active_window;
  313. extern  short   menu_item;
  314.  
  315. #endif
  316.  
  317. #ifdef __cplusplus
  318. }
  319. #endif
  320.  
  321.